home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / HYPERCAR / SYSENV__ / SYSENVIR.C next >
Text File  |  1988-11-24  |  7KB  |  295 lines

  1. /* SysEnvirons.c */
  2.  
  3. /*    SysEnvirons XFCN for HyperCard
  4.     with LightSpeedC v. 3.01 - 11/22/88
  5.                                                     Copyright 1988 by
  6.     Implements Macintosh SysEnvirons stuff            Sam Thornton
  7.                                                     PO Box 123
  8.     See SysEnvirons.docs for user interface            Fairfield NE 68938
  9.                                                     Some portions Copyright
  10.                                                     by Symantec and Apple.
  11.                                                     
  12.     NOTE:  All 'StringPtr' types in                    Compuserve: 71750,667
  13.            HyperXCmd.h and glue should                GEnie: S.THORNTON5
  14.            be dereferenced to type 'Ptr'
  15.            for this to compile properly.            May be copied and
  16.                                                     distributed for personal
  17.                                                     use without charge only,
  18.                                                     except for nominal
  19.                                                     distribution fees. For
  20.                                                     commercial use or
  21.                                                     distribution, contact
  22.                                                     author, above.    */
  23.  
  24.  
  25. #include "HyperXCmd.h"
  26. #include "SetUpA4.h"
  27. #include "MemoryMgr.h"
  28. #include "MacTypes.h"
  29. #include "unix.h"
  30. #include "FileMgr.h"
  31. #include "DeviceMgr.h"
  32. #include "OSUtil.h"
  33. #include "strings.h"
  34.  
  35. /* some constants for attribute requests */
  36. #define APPLETALK 1
  37. #define COLORQUICKDRAW 2
  38. #define FPU 3
  39. #define KEYBOARD 4
  40. #define MACHINE 5
  41. #define MEMORY 6
  42. #define PROCESSOR 7
  43. #define SYSTEM 8
  44. #define VERSION 9
  45.  
  46. /* keyword list for requests we recognize */
  47. typedef struct _k {
  48.     char    _word[15];
  49.     } _k;
  50.  
  51. _k _key[] = {
  52.     "appletalk",
  53.     "colorquickdraw",
  54.     "fpu",
  55.     "keyboard",
  56.     "machine",
  57.     "memory",
  58.     "processor",
  59.     "system",
  60.     "version",
  61. };
  62.  
  63. typedef struct trade_mark {
  64.     char    mk[90];
  65.     } trade_mark;
  66.     
  67. trade_mark mrk = {" SysEnvirons XFCN Copyright 1988 by Sam Thornton * PO Box 123 * Fairfield NE 68938 "};
  68.  
  69. pascal void main (paramPtr)
  70. XCmdBlockPtr    paramPtr;
  71.   {
  72.     int                    length;
  73.     Handle                answer;
  74.     char                temp_string[32];
  75.     SysEnvRec            environment;
  76.     Str255                my_machine;
  77.     
  78.       RememberA0();
  79.     SetUpA4();
  80.     
  81.     /* if no keyword or keyword too long, then abort */
  82.     if (paramPtr->paramCount != 1 || strlen(*paramPtr->params[0]) > 30) goto PANIC;
  83.  
  84.     /* keyword eval... */
  85.     length = lookup(paramPtr);
  86.     /* if the keyword is not recognized, then abort */
  87.     if (length == 0) goto PANIC;
  88.  
  89.     SysEnvirons(99,&environment); /* use a large v.num for force current */
  90.     
  91.     switch(length) {
  92.     
  93.         case VERSION: /* SysEnvirons version number request */
  94.             stci_d(my_machine, environment.environsVersion);
  95.             break;
  96.         
  97.         case MACHINE: /* Mac Model request */
  98.             switch(environment.machineType) {
  99.                 case envMachUnknown:
  100.                     strcpy(my_machine, "Unknown");
  101.                     break;
  102.                 case env512KE:
  103.                     strcpy(my_machine,"Macintosh 512KE");
  104.                     break;
  105.                 case envMacPlus:
  106.                     strcpy(my_machine,"Macintosh Plus");
  107.                     break;
  108.                 case envSE:
  109.                     strcpy(my_machine,"Macintosh SE");
  110.                     break;
  111.                 case envMacII:
  112.                     strcpy(my_machine,"Macintosh II");
  113.                     break;
  114.                 case envMac:
  115.                     strcpy(my_machine,"Macintosh 64K");
  116.                     break;
  117.                 case envXL:
  118.                     strcpy(my_machine,"Macintosh XL");
  119.                     break;
  120.                 default:
  121.                     strcpy(my_machine, "Unknown");
  122.                     break;
  123.                     
  124.                 } /* END MACHINE SWITCH */
  125.                 
  126.             break;
  127.  
  128.         case SYSTEM: /* System version request */
  129.         
  130.             switch(environment.systemVersion) {
  131.                 case 0:
  132.                     strcpy(my_machine, "Unknown");
  133.                     break;
  134.                 default:
  135.                     stci_d(temp_string, (environment.systemVersion & 0xFF00) >> 0x0008, 9);
  136.                     strcpy(my_machine, temp_string);
  137.                     strcat(my_machine, ".");
  138.                     stci_d(temp_string, (environment.systemVersion & 0x00F0) >> 0x0004, 9);
  139.                     strcat(my_machine, temp_string);
  140.                     if (environment.systemVersion & 0x000F) {
  141.                         strcat(my_machine, ".");
  142.                         stci_d(temp_string, environment.systemVersion & 0x000F, 9);
  143.                         strcat(my_machine, temp_string);
  144.                         }
  145.                     break;
  146.                 } /* END SYSTEM SWITCH */
  147.             break;
  148.  
  149.         case PROCESSOR: /* Processor type request */
  150.             
  151.             switch(environment.processor) {
  152.                 case envCPUUnknown:
  153.                     strcpy(my_machine, "Unknown");
  154.                     break;
  155.                 case env68000:
  156.                     strcpy(my_machine,"68000");
  157.                     break;
  158.                 case env68010:
  159.                     strcpy(my_machine,"68010");
  160.                     break;
  161.                 case env68020:
  162.                     strcpy(my_machine,"68020");
  163.                     break;
  164.                 default:
  165.                     strcpy(my_machine, "Unknown");
  166.                     break;
  167.             } /* END PROCESSOR SWITCH */
  168.             break;
  169.             
  170.         case FPU: /* FPU present request */
  171.         
  172.             if (environment.hasFPU)
  173.                 strcpy(my_machine,"installed");
  174.             else strcpy(my_machine,"not installed");
  175.             break;
  176.         
  177.         case COLORQUICKDRAW: /* ColorQD present request */
  178.         
  179.             if (environment.hasColorQD)
  180.                 strcpy(my_machine, "installed");
  181.             else strcpy(my_machine,"not installed");
  182.             break;
  183.         
  184.         case KEYBOARD: /* Model keyboard installed request */
  185.         
  186.             switch(environment.keyBoardType) {
  187.                 case envUnknownKbd:
  188.                     strcpy(my_machine, "Macintosh Plus Keyboard with keypad"); /* Looks screwy, but that╒s what Inside Mac sez */
  189.                     break;
  190.                 case envMacKbd:
  191.                     strcpy(my_machine, "Macintosh Keyboard");
  192.                     break;
  193.                 case envMacAndPad:
  194.                     strcpy(my_machine, "Macintosh Keyboard with keypad");
  195.                     break;
  196.                 case envMacPlusKbd:
  197.                     strcpy(my_machine, "Macintosh Plus Keyboard");
  198.                     break;
  199.                 case envAExtendKbd:
  200.                     strcpy(my_machine, "Apple Extended Keyboard");
  201.                     break;
  202.                 case envStandADBKbd:
  203.                     strcpy(my_machine, "ADB Keyboard");
  204.                     break;
  205.                 default:
  206.                     strcpy(my_machine, "Unknown");
  207.                     break;
  208.                 } /* END KEYBOARD SWITCH */
  209.                 
  210.             break;
  211.             
  212.         case APPLETALK: /* Appletalk version request */
  213.  
  214.             switch(environment.atDrvrVersNum) {
  215.                 case 0:
  216.                     strcpy(my_machine, "not installed");
  217.                     break;
  218.                 
  219.                 default:
  220.                     stci_d(temp_string, (environment.atDrvrVersNum & 0x0FF0) >> 0x0004, 9);
  221.                     strcpy(my_machine, temp_string);
  222.                     strcat(my_machine, ".");
  223.                     stci_d(temp_string, (environment.atDrvrVersNum & 0x000F), 9);
  224.                     strcat(my_machine, temp_string);
  225.                     break;
  226.                     
  227.                 } /* END APPLETALK SWITCH */
  228.                 
  229.             break;
  230.             
  231.         case MEMORY: /* Installed memory size request */
  232.  
  233.             NumToString(MemTop, &temp_string);
  234.             PtoCstr(temp_string);
  235.             strcat(temp_string, " / 1024");
  236.             CtoPstr(temp_string);
  237.             answer = EvalExpr(paramPtr, temp_string);
  238.             strcpy(my_machine, *answer);
  239.             DisposHandle(answer);
  240.             break;
  241.         
  242.         default:
  243.             break;
  244.             
  245.         } /* END OF MAIN SWITCH */
  246.         
  247.         
  248.         length = strlen(my_machine);
  249.         
  250.         if (length > 0) { /* we're bulletproof here */
  251.             paramPtr->returnValue = NewHandle(length + 1);
  252.             strcpy(*paramPtr->returnValue, my_machine);
  253.             goto NOPANIC;
  254.             }
  255.             
  256.     PANIC:
  257.         SysBeep(1);
  258.     NOPANIC:
  259.         RestoreA4();
  260.         return;
  261.     }
  262.     
  263. /* lookup routine - mod from CAPPS Toolbox lookup */
  264.  
  265. lookup(paramPtr)
  266. XCmdBlockPtr paramPtr;
  267. {
  268.     register    long i, j, x, last;
  269.     register    int dir;
  270.     char        temp_string[31];
  271.     
  272.     strcpy(temp_string, (*paramPtr->params[0]));
  273.     
  274.     dir = strlen(temp_string);
  275.  
  276.     for (; dir >= 0; dir--)
  277.         temp_string[dir] = tolower(temp_string[dir]);
  278.     
  279.     last = (sizeof(_key) / sizeof(struct _k)) - 1;
  280.  
  281.     for (i = 0, j = last; i <= j; ){
  282.         x = (i + j) >> 1;
  283.  
  284.         dir = strcmp(temp_string, &_key[x]._word[0]);
  285.         if (dir < 0)
  286.             j = x - 1;
  287.         else if (dir > 0)
  288.             i = x + 1;
  289.         else
  290.             return(x + 1);
  291.     }
  292.     return 0;
  293. }
  294.  
  295.